#include "ed_port.h"
#include "ed4e_utility.h"
#include "dev_common.h"
#include "dev_swi.h"

uint32_t System_GetTicks(void)
{
    HAL_GetTick();
}

static void _Lock(ED_Lock * const me)
{
    __disable_irq();
}

static void _Unlock(ED_Lock * const me)
{
    __enable_irq();
}

static void _Remove(void *me)
{
}

static ED_Lock g_edlock = {
    .lock = _Lock,
    .unlock = _Unlock,
    .remove = _Remove
};

ED_Lock *ED_Lock_Ctor(void)
{
    ED_Lock *me = &g_edlock;
    return me;
}

void ED4E_TriggerKeyEP(void)
{
    SCB->ICSR |= 1 << SCB_ICSR_PENDSVSET_Pos;
}

void ED4E_TriggerUrgentEP(void)
{
    NVIC->STIR = URGENT_IRQn;
}

void SysTick_Handler(void)
{
    HAL_IncTick();
    if (HAL_GetTick() % 10 == 0) {
        ED4E_KeyEP_WakeUp();
    }
}